package com.dengqi.mymodule.activity.network.module;

import com.dengqi.mymodule.activity.network.base.BasePresenter;
import com.dengqi.mymodule.activity.network.bean.CardBean;
import com.dengqi.mymodule.activity.network.bean.CardImgs_Data;
import com.dengqi.mymodule.activity.network.bean.MyCardBean;
import com.dengqi.mymodule.activity.network.bean.ServiceBean;
import com.dengqi.mymodule.activity.network.bean.SpecsBean;
import com.dengqi.mymodule.activity.network.bean.SubServer_Specs;
import com.dengqi.mymodule.activity.network.bean.TotalNum_Lists;
import com.module.retrofit.RetrofitHelper;
import com.module.retrofit.bean.ResponseBean;
import com.module.retrofit.callback.BaseObserver;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import java.util.LinkedHashMap;
import java.util.Map;


/**
 * @Author: dengqi
 * @CreateDate: 2020-10-15 19:51
 * @Description:
 */
public class CardPresenter extends BasePresenter implements CardContract.Presenter {

    private CardContract.Model model;
    private int page = 1;
    private int pageSize = 10;

    public CardPresenter(RxAppCompatActivity activity){
        super(activity);
        this.model = RetrofitHelper.getApiService(CardContract.Model.class);
    }

    @Override
    public void getCardList(CardContract.CardView view) {
        String cardType = view.getCardType();
        Map<String, String> parmas = new LinkedHashMap<>();
        parmas.put("shopId", view.getShopId());
        parmas.put("page", String.valueOf(page));
        parmas.put("pageSize", String.valueOf(pageSize));
        parmas.put("status", view.getStatus_());

        if("1".equals(cardType)){
            execute(model.getShopSinglePage(parmas))
                    .subscribe(new BaseObserver<ResponseBean<TotalNum_Lists<ServiceBean>>>(activity) {
                        @Override
                        public void onSuccess(ResponseBean<TotalNum_Lists<ServiceBean>> result) {
                            view.onServiceList(result.getData().getList());

                        }

                    });
        }else if("2".equals(cardType)){
            execute(model.getShopSmPage(parmas))
                    .subscribe(new BaseObserver<ResponseBean<TotalNum_Lists<CardBean>>>(activity) {
                        @Override
                        public void onSuccess(ResponseBean<TotalNum_Lists<CardBean>> result) {
                            view.onCardList(result.getData().getList());

                        }

                    });
        }else if("3".equals(cardType)){
            execute(model.getShopCardPage(parmas))
                    .subscribe(new BaseObserver<ResponseBean<TotalNum_Lists<CardBean>>>(activity) {
                        @Override
                        public void onSuccess(ResponseBean<TotalNum_Lists<CardBean>> result) {
                            view.onCardList(result.getData().getList());

                        }

                    });
        }else if("4".equals(cardType)){
            execute(model.getShopHcardPage(parmas))
                    .subscribe(new BaseObserver<ResponseBean<TotalNum_Lists<CardBean>>>(activity) {
                        @Override
                        public void onSuccess(ResponseBean<TotalNum_Lists<CardBean>> result) {
                            view.onCardList(result.getData().getList());

                        }

                    });
        }else if("5".equals(cardType)){
            execute(model.getShopNCardPage(parmas))
                    .subscribe(new BaseObserver<ResponseBean<TotalNum_Lists<CardBean>>>(activity) {
                        @Override
                        public void onSuccess(ResponseBean<TotalNum_Lists<CardBean>> result) {
                            view.onCardList(result.getData().getList());

                        }

                    });
        }else if("6".equals(cardType)){
            execute(model.getShopHNCardPage(parmas))
                    .subscribe(new BaseObserver<ResponseBean<TotalNum_Lists<CardBean>>>(activity) {
                        @Override
                        public void onSuccess(ResponseBean<TotalNum_Lists<CardBean>> result) {
                            view.onCardList(result.getData().getList());

                        }

                    });
        }

    }

    @Override
    public void getMyCardList(CardContract.MyCardView view) {
        Map<String, String> parmas = new LinkedHashMap<>();
        parmas.put("uid", view.getUid());
        parmas.put("shopId", view.getShopId());
        parmas.put("cardPackageType", view.getCardType());
        parmas.put("cardPackageStatus", view.getCardStatus());
        parmas.put("page", String.valueOf(page));
        parmas.put("pageSize", String.valueOf(pageSize));
        execute(model.getMyCardPage(parmas))
                .subscribe(new BaseObserver<ResponseBean<CardImgs_Data<TotalNum_Lists<MyCardBean>>>>(activity) {
                    @Override
                    public void onSuccess(ResponseBean<CardImgs_Data<TotalNum_Lists<MyCardBean>>> result) {
                        view.onMyCardList(result.getData().getData().getList());
                    }

                });
    }

    @Override
    public void getSpecsListBySingleId(CardContract.SpecsView view) {
        Map<String, String> parmas = new LinkedHashMap<>();
        parmas.put("singleId", view.getSingleId());
        parmas.put("shopId", view.getShopId());
        execute(model.getSpecsBySingleId(parmas))
                .subscribe(new BaseObserver<ResponseBean<SubServer_Specs<SpecsBean>>>(activity) {
                    @Override
                    public void onSuccess(ResponseBean<SubServer_Specs<SpecsBean>> result) {
                        view.onSpecsListBySingleId(result.getData().getSpecs());
                    }

                });
    }
}
